package gui;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


import model.Field;

public class MainWindow extends JFrame
{
	private static final long serialVersionUID = 1L;

	public JLabel south_label;
	
	BoardPanel d_boardPanel;
	SettingsPanel d_settingsPanel;
	
	public MainWindow(SettingsPanel settingsPanel, BoardPanel boardPanel)
	{
		super("Othello");
		
		d_boardPanel = boardPanel;
		d_settingsPanel = settingsPanel;
		
		getContentPane().setLayout(new BorderLayout());

		{//NORTH panel
			getContentPane().add(settingsPanel, BorderLayout.NORTH);
		}
		{//CENTER panel
			getContentPane().add(boardPanel, BorderLayout.CENTER);
		}
		{//SOUTH panel
			JPanel panel_south = new JPanel();
			
			south_label = new JLabel("Press play to start");
			panel_south.add(south_label);
			
			getContentPane().add(panel_south, BorderLayout.SOUTH);
		}
		
        pack();
        setVisible(true);
        setResizable(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	public void updateBoard(byte color) 
	{// set to newest information
		d_boardPanel.updateBoard(color);
		String info = Field.toString(Field.WHITE) + " " + d_boardPanel.d_board.getScore(Field.WHITE) + " - ";
		info += d_boardPanel.d_board.getScore(Field.BLACK) + " " + Field.toString(Field.BLACK);
		info += "       " + Field.toString(color) + " is thinking ... ";
		south_label.setText(info);
		repaint();
	}

	public void updateFinalBoard() 
	{// special treatment for final board
		d_boardPanel.updateFinalBoard();
		int whiteStones = d_boardPanel.d_board.getScore(Field.WHITE);
		int blackStones = d_boardPanel.d_board.getScore(Field.BLACK);
		String info = Field.toString(d_boardPanel.d_board.bestPlayer()) + " has won" + " with " + whiteStones + " - " + blackStones;
		south_label.setText(info);
		repaint();	
	}
}
